1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"1038.25">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #0000bf}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #007300}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #bf0000}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
18 p
.p9
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; color: #0000ee}
19 span
.s1
{color: #0000ee}
20 span
.s2
{color: #0000bf}
21 span
.s3
{color: #000000}
22 span
.s4
{color: #007300}
23 span
.s5
{font: 12.0px Helvetica
}
24 span
.Apple-tab-span
{white-space:pre
}
28 <p class=
"p1"><b>Creating variations on a base rhythmic pattern
</b></p>
29 <p class=
"p2"><br></p>
30 <p class=
"p3">Normally patterns are stateless objects. This would seem to rule out the possibility of making on-the-fly changes to the material that pattern is playing. Indeed, modifying an existing pattern object is tricky and not always appropriate (because that approach cannot confine its changes to the one stream making the changes).
</p>
31 <p class=
"p2"><br></p>
32 <p class=
"p3"><span class=
"s1"><a href=
"../Patterns/Plazy.html"><b>Plazy
</b></a></span> offers an alternate approach: use a function to generate a new pattern object periodically, and play these patterns in succession, one by one. (Plazy embeds just one pattern; wrapping Plazy in
<a href=
"../Patterns/Pn.html"><span class=
"s2">Pn
</span></a> does it many times.)
</p>
33 <p class=
"p2"><br></p>
34 <p class=
"p3">The logic in this example is a bit more involved: for each measure, start with arrays containing the basic rhythmic pattern for each part (kick drum, snare and hi-hat) and insert ornamental notes with different amplitudes and durations. Arrays hold the rhythmic data because this type of rhythm generation calls for awareness of the entire bar (future), whereas patterns generally don't look ahead.
</p>
35 <p class=
"p2"><br></p>
36 <p class=
"p3">This suggests an object for data storage that will also encapsulate the unique logic for each part. We saw earlier that
<a href=
"../Patterns/Penvir.html"><span class=
"s2">Penvir
</span></a> maintains a distinct environment for each stream made from the pattern. In other words, Penvir allows more complicated behavior to be modeled using an object that encapsulates both custom logic and the data on which it will operate.
</p>
37 <p class=
"p2"><br></p>
38 <p class=
"p3">The specific ornaments to be added are slightly different for the three parts, so there are three environments. Some functions are shared; rather than copy and paste them into each environment, we put them into a separate environment and use that as the parent of the environment for each drum part.
</p>
39 <p class=
"p2"><br></p>
40 <p class=
"p3">Most of the logic is in the drum parts' environments, and consist mostly of straightforward array manipulations. Let's unpack the pattern that uses the environments to generate notes:
</p>
41 <p class=
"p2"><br></p>
42 <p class=
"p4">~kik =
<span class=
"s2">Penvir
</span>(~kikEnvir,
<span class=
"s2">Pn
</span>(
<span class=
"s2">Plazy
</span>({
</p>
43 <p class=
"p4"><span class=
"Apple-tab-span"> </span>~init.value;
</p>
44 <p class=
"p4"><span class=
"Apple-tab-span"> </span>~addNotes.value;
</p>
45 <p class=
"p5"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>Pbindf
<span class=
"s3">(
</span></p>
46 <p class=
"p5"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>Pbind
<span class=
"s3">(
</span></p>
47 <p class=
"p6"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>\instrument
<span class=
"s3">,
</span>\kik
<span class=
"s3">,
</span></p>
48 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">\preamp
</span>,
0.4,
</p>
49 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">\dur
</span>,
0.25,
</p>
50 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>*(~pbindPairs.value(#[amp, decay2]))
</p>
51 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>),
</p>
52 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">\freq
</span>,
<span class=
"s2">Pif
</span>(
<span class=
"s2">Pkey
</span>(
<span class=
"s4">\amp
</span>)
> 0,
1,
<span class=
"s4">\rest
</span>)
</p>
53 <p class=
"p4"><span class=
"Apple-tab-span"> </span>)
</p>
54 <p class=
"p4">}),
<span class=
"s2">inf
</span>)).play(quant:
4);
</p>
55 <p class=
"p2"><br></p>
56 <p class=
"p3"><b>Penvir(~kikEnvir, ...)
</b> : Tell the enclosed pattern to run inside the kick drum's environment.
</p>
57 <p class=
"p2"><br></p>
58 <p class=
"p3"><b>Pn(..., inf)
</b> : Repeat the enclosed pattern (Plazy) an infinite number of times.
</p>
59 <p class=
"p2"><br></p>
60 <p class=
"p3"><b>Plazy({ ... })
</b> : The function can do anything it likes, as long as it returns some kind of pattern. The first two lines of the function do the hard work, especially ~addNotes.value, calling into the environment to use the rhythm generator code. This changes the data in the environment, which then get plugged into Pbind in the ~pbindPairs.value() line. That pattern will play through; when it ends, Plazy gives control back to its parent -- Pn, which repeats Plazy.
</p>
61 <p class=
"p2"><br></p>
62 <p class=
"p3"><b>Pbindf(..., \freq, ...)
</b> : Pbindf adds new values into events coming from a different pattern. This usage is to take advantage of a fact about the default event. If the \freq key is a symbol (rather than a number or array), the event represents a rest and nothing will play on the server. It doesn't matter whether or not the SynthDef has a 'freq' control; a symbol in this space produces a rest. Here it's a simple conditional to produce a rest when amp ==
0.
</p>
63 <p class=
"p2"><br></p>
64 <p class=
"p3"><b>Pbind(...)
</b> : The meat of the notes: SynthDef name, general parameters, and rhythmic values from the environment. (The * syntax explains the need for Pbindf. The \freq expression must follow the pbindPairs result, but it isn't possible to put additional arguments after *(...). Pbindf allows the inner Pbind to be closed while still accepting additional values.)
</p>
65 <p class=
"p2"><br></p>
66 <p class=
"p3"><b>Third-party extension alert:
</b> This type of hybrid between pattern-style flow of control and object-oriented modeling is powerful but has some limitations, mainly difficulty with inheritance (subclassing). The ddwChucklib quark (which depends on ddwPrototype) expands the object-oriented modeling possibilities while supporting patterns' ability to work with data external to a pattern itself.
</p>
67 <p class=
"p2"><br></p>
68 <p class=
"p2"><br></p>
70 <p class=
"p7">// this kick drum doesn't sound so good on cheap speakers
</p>
71 <p class=
"p7">// but if your monitors have decent bass, it's electro-licious
</p>
72 <p class=
"p5">SynthDef
<span class=
"s3">(
</span><span class=
"s4">\kik
</span><span class=
"s3">, {
</span>|basefreq =
50, ratio =
7, sweeptime =
0.05, preamp =
1, amp =
1,
</p>
73 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>decay1 =
0.3, decay1L =
0.8, decay2 =
0.15, out|
</p>
74 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"s2">var
</span><span class=
"Apple-tab-span"> </span>fcurve =
<span class=
"s2">EnvGen
</span>.kr(
<span class=
"s2">Env
</span>([basefreq * ratio, basefreq], [sweeptime],
<span class=
"s4">\exp
</span>)),
</p>
75 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>env =
<span class=
"s2">EnvGen
</span>.kr(
<span class=
"s2">Env
</span>([
1, decay1L,
0], [decay1, decay2], -
4), doneAction:
2),
</p>
76 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>sig =
<span class=
"s2">SinOsc
</span>.ar(fcurve,
0.5pi, preamp).distort * env * amp;
</p>
77 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"s2">Out
</span>.ar(out, sig !
2)
</p>
78 <p class=
"p4">}).add;
</p>
79 <p class=
"p8"><br></p>
80 <p class=
"p5">SynthDef
<span class=
"s3">(
</span><span class=
"s4">\kraftySnr
</span><span class=
"s3">, {
</span>|amp =
1, freq =
2000, rq =
3, decay =
0.3, pan, out|
</p>
81 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"s2">var
</span><span class=
"Apple-tab-span"> </span>sig =
<span class=
"s2">PinkNoise
</span>.ar(amp),
</p>
82 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>env =
<span class=
"s2">EnvGen
</span>.kr(
<span class=
"s2">Env
</span>.perc(
0.01, decay), doneAction:
2);
</p>
83 <p class=
"p4"><span class=
"Apple-tab-span"> </span>sig =
<span class=
"s2">BPF
</span>.ar(sig, freq, rq, env);
</p>
84 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"s2">Out
</span>.ar(out,
<span class=
"s2">Pan2
</span>.ar(sig, pan))
</p>
85 <p class=
"p4">}).add;
</p>
86 <p class=
"p8"><br></p>
87 <p class=
"p4">~commonFuncs = (
</p>
88 <p class=
"p7"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// save starting time, to recognize the last bar of a
4-bar cycle
</p>
89 <p class=
"p4"><span class=
"Apple-tab-span"> </span>init: {
</p>
90 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>if(~startTime.isNil) { ~startTime =
<span class=
"s2">thisThread
</span>.clock.beats };
</p>
91 <p class=
"p4"><span class=
"Apple-tab-span"> </span>},
</p>
92 <p class=
"p7"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// convert the rhythm arrays into patterns
</p>
93 <p class=
"p4"><span class=
"Apple-tab-span"> </span>pbindPairs: {
<span class=
"s2">|keys|
</span></p>
94 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">var
</span><span class=
"Apple-tab-span"> </span>pairs =
<span class=
"s2">Array
</span>(keys.size *
2);
</p>
95 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>keys.do({
<span class=
"s2">|key|
</span></p>
96 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>if(key.envirGet.notNil) { pairs.add(key).add(
<span class=
"s2">Pseq
</span>(key.envirGet,
1)) };
</p>
97 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
98 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>pairs
</p>
99 <p class=
"p4"><span class=
"Apple-tab-span"> </span>},
</p>
100 <p class=
"p7"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// identify rests in the rhythm array
</p>
101 <p class=
"p7"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// (to know where to stick notes in)
</p>
102 <p class=
"p4"><span class=
"Apple-tab-span"> </span>getRestIndices: {
<span class=
"s2">|array|
</span></p>
103 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">var
</span><span class=
"Apple-tab-span"> </span>result =
<span class=
"s2">Array
</span>(array.size);
</p>
104 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>array.do({
<span class=
"s2">|item, i|
</span></p>
105 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>if(item ==
0) { result.add(i) }
</p>
106 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
107 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>result
</p>
108 <p class=
"p4"><span class=
"Apple-tab-span"> </span>}
</p>
111 <p class=
"p8"><br></p>
113 <p class=
"p4"><span class=
"s2">TempoClock
</span>.default.tempo =
104 /
60;
</p>
114 <p class=
"p8"><br></p>
115 <p class=
"p4">~kikEnvir = (
</p>
116 <p class=
"p4"><span class=
"Apple-tab-span"> </span>parent: ~commonFuncs,
</p>
117 <p class=
"p7"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// rhythm pattern that is constant in each bar
</p>
118 <p class=
"p4"><span class=
"Apple-tab-span"> </span>baseAmp: #[
1,
0,
0,
0,
<span class=
"Apple-converted-space">Â
</span>0,
0,
0.7,
0,
<span class=
"Apple-converted-space">Â
</span>0,
1,
0,
0,
<span class=
"Apple-converted-space">Â
</span>0,
0,
0,
0] *
0.5,
</p>
119 <p class=
"p4"><span class=
"Apple-tab-span"> </span>baseDecay: #[
0.15,
0,
0,
0,
<span class=
"Apple-converted-space">Â
</span>0,
0,
0.15,
0,
<span class=
"Apple-converted-space">Â
</span>0,
0.15,
0,
0,
<span class=
"Apple-converted-space">Â
</span>0,
0,
0,
0],
</p>
120 <p class=
"p4"><span class=
"Apple-tab-span"> </span>addNotes: {
</p>
121 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">var
</span><span class=
"Apple-tab-span"> </span>beat16pos = (
<span class=
"s2">thisThread
</span>.clock.beats - ~startTime) %
16,
</p>
122 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>available = ~getRestIndices.(~baseAmp);
</p>
123 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~amp = ~baseAmp.copy;
</p>
124 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~decay2 = ~baseDecay.copy;
</p>
125 <p class=
"p7"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// if last bar of
4beat cycle, do busier fills
</p>
126 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>if(beat16pos.inclusivelyBetween(
12,
16)) {
</p>
127 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>available.scramble[..rrand(
5,
10)].do({
<span class=
"s2">|index|
</span></p>
128 <p class=
"p7"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// crescendo
</p>
129 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~amp[index] = index.linexp(
0,
15,
0.2,
0.5);
</p>
130 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~decay2[index] =
0.15;
</p>
131 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
132 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>} {
</p>
133 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>available.scramble[..rrand(
0,
2)].do({
<span class=
"s2">|index|
</span></p>
134 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~amp[index] = rrand(
0.15,
0.3);
</p>
135 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~decay2[index] = rrand(
0.05,
0.1);
</p>
136 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
137 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>}
</p>
138 <p class=
"p4"><span class=
"Apple-tab-span"> </span>}
</p>
140 <p class=
"p8"><br></p>
141 <p class=
"p4">~snrEnvir = (
</p>
142 <p class=
"p4"><span class=
"Apple-tab-span"> </span>parent: ~commonFuncs,
</p>
143 <p class=
"p4"><span class=
"Apple-tab-span"> </span>baseAmp: #[
0,
0,
0,
0,
<span class=
"Apple-converted-space">Â
</span>1,
0,
0,
0,
<span class=
"Apple-converted-space">Â
</span>0,
0,
0,
0,
<span class=
"Apple-converted-space">Â
</span>1,
0,
0,
0] *
1.5,
</p>
144 <p class=
"p4"><span class=
"Apple-tab-span"> </span>baseDecay: #[
0,
0,
0,
0,
<span class=
"Apple-converted-space">Â
</span>0.7,
0,
0,
0,
<span class=
"Apple-converted-space">Â
</span>0,
0,
0,
0,
<span class=
"Apple-converted-space">Â
</span>0.4,
0,
0,
0],
</p>
145 <p class=
"p4"><span class=
"Apple-tab-span"> </span>addNotes: {
</p>
146 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">var
</span><span class=
"Apple-tab-span"> </span>beat16pos = (
<span class=
"s2">thisThread
</span>.clock.beats - ~startTime) %
16,
</p>
147 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>available = ~getRestIndices.(~baseAmp),
</p>
148 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>choice;
</p>
149 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~amp = ~baseAmp.copy;
</p>
150 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~decay = ~baseDecay.copy;
</p>
151 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>if(beat16pos.inclusivelyBetween(
12,
16)) {
</p>
152 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>available.scramble[..rrand(
5,
9)].do({
<span class=
"s2">|index|
</span></p>
153 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~amp[index] = index.linexp(
0,
15,
0.5,
1.8);
</p>
154 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~decay[index] = rrand(
0.2,
0.4);
</p>
155 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
156 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>} {
</p>
157 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>available.scramble[..rrand(
1,
3)].do({
<span class=
"s2">|index|
</span></p>
158 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~amp[index] = rrand(
0.15,
0.3);
</p>
159 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~decay[index] = rrand(
0.2,
0.4);
</p>
160 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
161 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>}
</p>
162 <p class=
"p4"><span class=
"Apple-tab-span"> </span>}
</p>
164 <p class=
"p8"><br></p>
165 <p class=
"p4">~hhEnvir = (
</p>
166 <p class=
"p4"><span class=
"Apple-tab-span"> </span>parent: ~commonFuncs,
</p>
167 <p class=
"p4"><span class=
"Apple-tab-span"> </span>baseAmp:
15 !
16,
</p>
168 <p class=
"p4"><span class=
"Apple-tab-span"> </span>baseDelta:
0.25 !
16,
</p>
169 <p class=
"p4"><span class=
"Apple-tab-span"> </span>addNotes: {
</p>
170 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">var
</span><span class=
"Apple-tab-span"> </span>beat16pos = (
<span class=
"s2">thisThread
</span>.clock.beats - ~startTime) %
16,
</p>
171 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>available = (
0.
.15),
</p>
172 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>toAdd;
</p>
173 <p class=
"p7"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// if last bar of
4beat cycle, do busier fills
</p>
174 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~amp = ~baseAmp.copy;
</p>
175 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~dur = ~baseDelta.copy;
</p>
176 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>if(beat16pos.inclusivelyBetween(
12,
16)) {
</p>
177 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>toAdd = available.scramble[..rrand(
2,
5)]
</p>
178 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>} {
</p>
179 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>toAdd = available.scramble[..rrand(
0,
1)]
</p>
180 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>};
</p>
181 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>toAdd.do({
<span class=
"s2">|index|
</span></p>
182 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~amp[index] = ~doubleTimeAmps;
</p>
183 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>~dur[index] = ~doubleTimeDurs;
</p>
184 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
185 <p class=
"p4"><span class=
"Apple-tab-span"> </span>},
</p>
186 <p class=
"p4"><span class=
"Apple-tab-span"> </span>doubleTimeAmps:
<span class=
"s2">Pseq
</span>(#[
15,
10],
1),
</p>
187 <p class=
"p4"><span class=
"Apple-tab-span"> </span>doubleTimeDurs:
<span class=
"s2">Pn
</span>(
0.125,
2)
</p>
189 <p class=
"p8"><br></p>
190 <p class=
"p8"><br></p>
191 <p class=
"p4">~kik =
<span class=
"s2">Penvir
</span>(~kikEnvir,
<span class=
"s2">Pn
</span>(
<span class=
"s2">Plazy
</span>({
</p>
192 <p class=
"p4"><span class=
"Apple-tab-span"> </span>~init.value;
</p>
193 <p class=
"p4"><span class=
"Apple-tab-span"> </span>~addNotes.value;
</p>
194 <p class=
"p5"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>Pbindf
<span class=
"s3">(
</span></p>
195 <p class=
"p5"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>Pbind
<span class=
"s3">(
</span></p>
196 <p class=
"p6"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>\instrument
<span class=
"s3">,
</span>\kik
<span class=
"s3">,
</span></p>
197 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">\preamp
</span>,
0.4,
</p>
198 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">\dur
</span>,
0.25,
</p>
199 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>*(~pbindPairs.value(#[amp, decay2]))
</p>
200 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>),
</p>
201 <p class=
"p7"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// default Event checks \freq --
</p>
202 <p class=
"p7"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// if a symbol like \rest or even just \,
</p>
203 <p class=
"p7"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// the event is a rest and no synth will be played
</p>
204 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">\freq
</span>,
<span class=
"s2">Pif
</span>(
<span class=
"s2">Pkey
</span>(
<span class=
"s4">\amp
</span>)
> 0,
1,
<span class=
"s4">\rest
</span>)
</p>
205 <p class=
"p4"><span class=
"Apple-tab-span"> </span>)
</p>
206 <p class=
"p4">}),
<span class=
"s2">inf
</span>)).play(quant:
4);
</p>
207 <p class=
"p8"><br></p>
208 <p class=
"p4">~snr =
<span class=
"s2">Penvir
</span>(~snrEnvir,
<span class=
"s2">Pn
</span>(
<span class=
"s2">Plazy
</span>({
</p>
209 <p class=
"p4"><span class=
"Apple-tab-span"> </span>~init.value;
</p>
210 <p class=
"p4"><span class=
"Apple-tab-span"> </span>~addNotes.value;
</p>
211 <p class=
"p5"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>Pbindf
<span class=
"s3">(
</span></p>
212 <p class=
"p5"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>Pbind
<span class=
"s3">(
</span></p>
213 <p class=
"p6"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>\instrument
<span class=
"s3">,
</span>\kraftySnr
<span class=
"s3">,
</span></p>
214 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">\dur
</span>,
0.25,
</p>
215 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>*(~pbindPairs.value(#[amp, decay]))
</p>
216 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>),
</p>
217 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">\freq
</span>,
<span class=
"s2">Pif
</span>(
<span class=
"s2">Pkey
</span>(
<span class=
"s4">\amp
</span>)
> 0,
5000,
<span class=
"s4">\rest
</span>)
</p>
218 <p class=
"p4"><span class=
"Apple-tab-span"> </span>)
</p>
219 <p class=
"p4">}),
<span class=
"s2">inf
</span>)).play(quant:
4);
</p>
220 <p class=
"p8"><br></p>
221 <p class=
"p4">~hh =
<span class=
"s2">Penvir
</span>(~hhEnvir,
<span class=
"s2">Pn
</span>(
<span class=
"s2">Plazy
</span>({
</p>
222 <p class=
"p4"><span class=
"Apple-tab-span"> </span>~init.value;
</p>
223 <p class=
"p4"><span class=
"Apple-tab-span"> </span>~addNotes.value;
</p>
224 <p class=
"p5"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>Pbindf
<span class=
"s3">(
</span></p>
225 <p class=
"p5"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>Pbind
<span class=
"s3">(
</span></p>
226 <p class=
"p6"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>\instrument
<span class=
"s3">,
</span>\kraftySnr
<span class=
"s3">,
</span></p>
227 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">\rq
</span>,
0.06,
</p>
228 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">\amp
</span>,
15,
</p>
229 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">\decay
</span>,
0.04,
</p>
230 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>*(~pbindPairs.value(#[amp, dur]))
</p>
231 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>),
</p>
232 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s4">\freq
</span>,
<span class=
"s2">Pif
</span>(
<span class=
"s2">Pkey
</span>(
<span class=
"s4">\amp
</span>)
> 0,
12000,
<span class=
"s4">\rest
</span>)
</p>
233 <p class=
"p4"><span class=
"Apple-tab-span"> </span>)
</p>
234 <p class=
"p4">}),
<span class=
"s2">inf
</span>)).play(quant:
4);
</p>
236 <p class=
"p8"><br></p>
237 <p class=
"p7">// stop just before barline
</p>
238 <p class=
"p4">t =
<span class=
"s2">TempoClock
</span>.default;
</p>
239 <p class=
"p4">t.schedAbs(t.nextTimeOnGrid(
4, -
0.001), {
</p>
240 <p class=
"p4"><span class=
"Apple-tab-span"> </span>[~kik, ~snr, ~hh].do(
<span class=
"s2">_
</span>.stop);
</p>
241 <p class=
"p4">});
</p>
242 <p class=
"p2"><br></p>
243 <p class=
"p2"><br></p>
244 <p class=
"p9"><span class=
"s3">Previous:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><a href=
"PG_Cookbook06_Phrase_Network.html"><span class=
"s5">PG_Cookbook06_Phrase_Network
</span></a></span></p>
245 <p class=
"p9"><span class=
"s3">Next:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><a href=
"PG_Ref01_Pattern_Internals.html"><span class=
"s5">PG_Ref01_Pattern_Internals
</span></a></span></p>